<template>
  <div>
    <!-- 子Tab -->
    <el-tabs v-model="activeSubTab" type="card" class="sub-tabs">
      <el-tab-pane label="短板科目识别" name="weakness-identification">
        <template #label>
          <div class="flex items-center">
            <div class="i-mdi:alert-circle w-4 h-4 mr-2 text-red-500"></div>
            <span>短板科目识别</span>
          </div>
        </template>
      </el-tab-pane>

      <el-tab-pane label="成绩稳定性分析" name="stability-analysis">
        <template #label>
          <div class="flex items-center">
            <div class="i-mdi:chart-line-variant w-4 h-4 mr-2 text-orange-500"></div>
            <span>成绩稳定性分析</span>
          </div>
        </template>
      </el-tab-pane>

      <el-tab-pane label="提分潜力分析" name="potential-analysis">
        <template #label>
          <div class="flex items-center">
            <div class="i-mdi:trending-up w-4 h-4 mr-2 text-green-500"></div>
            <span>提分潜力分析</span>
          </div>
        </template>
      </el-tab-pane>
    </el-tabs>

    <!-- 内容区域 -->
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
      <div v-if="activeSubTab === 'weakness-identification'">
        <WeaknessIdentification :weakness-data="weaknessData" ref="weaknessIdentificationRef" />
      </div>
      <div v-else-if="activeSubTab === 'stability-analysis'">
        <StabilityAnalysis :stability-data="stabilityData" ref="stabilityAnalysisRef" />
      </div>
      <div v-else-if="activeSubTab === 'potential-analysis'">
        <PotentialAnalysis :potential-data="potentialData" ref="potentialAnalysisRef" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import WeaknessIdentification from './WeaknessIdentification.vue'
import StabilityAnalysis from './StabilityAnalysis.vue'
import PotentialAnalysis from './PotentialAnalysis.vue'
import { getStabilityAnalysis } from '@/api/student/stability'

// 当前激活的子Tab
const activeSubTab = ref('weakness-identification')

// 组件引用
const weaknessIdentificationRef = ref(null)
const stabilityAnalysisRef = ref(null)
const potentialAnalysisRef = ref(null)

// 短板科目识别数据
const weaknessData = {
  subjects: [
    { name: '数学', score: 75, averageScore: 82, gap: -7, percentage: -8.5, isWeakness: true },
    { name: '英语', score: 88, averageScore: 85, gap: 3, percentage: 3.5, isWeakness: false },
    { name: '语文', score: 92, averageScore: 88, gap: 4, percentage: 4.5, isWeakness: false },
    { name: '物理', score: 78, averageScore: 80, gap: -2, percentage: -2.5, isWeakness: false },
    { name: '化学', score: 82, averageScore: 83, gap: -1, percentage: -1.2, isWeakness: false },
    { name: '生物', score: 85, averageScore: 84, gap: 1, percentage: 1.2, isWeakness: false }
  ],
  weaknessSubjects: ['数学'],
  developmentIndex: 7.2, // 综合发展指数
  recommendations: [
    '数学科目需要重点关注，建议增加练习时间',
    '可以寻求老师或同学的帮助，加强基础知识点',
    '建议制定数学专项学习计划'
  ]
}

// 成绩稳定性分析数据
const stabilityData = ref({
  subjects: [],
  unstableSubjects: [],
  recommendations: []
})

// 加载稳定性分析数据
const loadStabilityData = async () => {
  try {
    const response = await getStabilityAnalysis({ studentId: '123' }) // 这里可以根据实际需要传入学生ID
    if (response.code === 200) {
      stabilityData.value = response.data
    }
  } catch (error) {
    console.error('加载稳定性分析数据失败:', error)
  }
}

// 组件挂载时加载数据
onMounted(() => {
  loadStabilityData()
})

// 提分潜力分析数据
const potentialData = {
  subjects: [
    {
      name: '数学',
      potentialScore: 9.2,
      currentScore: 75,
      averageScore: 82,
      gapToAverage: -7,
      studentDistribution: 'concentrated',
      expectedImprovement: 12,
      timeInvestment: 'high',
      priority: 1
    },
    {
      name: '物理',
      potentialScore: 7.8,
      currentScore: 78,
      averageScore: 80,
      gapToAverage: -2,
      studentDistribution: 'moderate',
      expectedImprovement: 6,
      timeInvestment: 'medium',
      priority: 2
    },
    {
      name: '化学',
      potentialScore: 6.5,
      currentScore: 82,
      averageScore: 83,
      gapToAverage: -1,
      studentDistribution: 'concentrated',
      expectedImprovement: 4,
      timeInvestment: 'low',
      priority: 3
    },
    {
      name: '英语',
      potentialScore: 5.2,
      currentScore: 88,
      averageScore: 85,
      gapToAverage: 3,
      studentDistribution: 'scattered',
      expectedImprovement: 2,
      timeInvestment: 'low',
      priority: 4
    },
    {
      name: '语文',
      potentialScore: 4.8,
      currentScore: 92,
      averageScore: 88,
      gapToAverage: 4,
      studentDistribution: 'scattered',
      expectedImprovement: 1,
      timeInvestment: 'low',
      priority: 5
    },
    {
      name: '生物',
      potentialScore: 5.5,
      currentScore: 85,
      averageScore: 84,
      gapToAverage: 1,
      studentDistribution: 'moderate',
      expectedImprovement: 3,
      timeInvestment: 'low',
      priority: 6
    }
  ],
  recommendations: [
    '数学科目提分潜力最大，建议优先投入学习时间',
    '物理科目也有不错的提分空间，可以作为第二重点',
    '建议制定详细的学习计划，合理分配各科目学习时间'
  ],
  studyPlan: {
    math: { hoursPerWeek: 8, focusAreas: ['基础概念', '解题技巧', '错题整理'] },
    physics: { hoursPerWeek: 5, focusAreas: ['公式记忆', '实验理解', '题型练习'] },
    chemistry: { hoursPerWeek: 3, focusAreas: ['概念理解', '计算练习'] }
  }
}
</script>

<style lang="scss" scoped>
// 子Tab样式
:deep(.sub-tabs) {
  .el-tabs__content {
    padding: 20px;
  }
}
:deep(.el-tabs__content) {
  padding: 0 !important;
}
</style> 